import Feature from 'ol/Feature'
import MultiPolygon from 'ol/geom/MultiPolygon'
import { isObject, isArray } from '../utils/index'
import { v4 as uuidv4 } from 'uuid'

/**
 * 描边
 * @param {*} opts
 */
export const multiPolygon = opts => {
  if (!isObject(opts) || !isArray(opts.data) || !opts.data.length) {
    throw new Error('addMultiPolygon 参数错误')
  }
  const id = opts.id || uuidv4()
  const polygon = new Feature({
    id,
    type: 'multiPolygon',
    name: opts.name,
    property: { ...opts },
    geometry: new MultiPolygon([opts.data])
  })
  return {
    features: [polygon],
    ids: [id]
  }
}